/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package UnitTest;

import junit.framework.TestCase;
import Model.Usuario;
import DB.DBManager;
import DB.Usuario.ControllerUsuario;
import java.sql.SQLException;
import static junit.framework.TestCase.assertEquals;

/**
 *
 * @author KZA
 */
public class TesteUsuario extends TestCase {
    
    DBManager db;
    
    public TesteUsuario(String testName, DBManager db) {
        super(testName);
        this.db = db;
    }

    public void testeUsuario() {
        System.out.println("* Unit_Test: I testeUsuario");

        Usuario user = new Usuario("Alcione", "Alcione55", "negaodetirarochapeu", 1, "21515151515", "al.cione@gmail.com",
                "02021972", "Alcioninha", "Mulherona", "Rua da Alcione", "Paris", "SP", "Brasil",
                "87240-364", "01177777777", "01188888888");

        assertEquals("Alcione",             user.getNome());
        assertEquals("Alcione55",           user.getUsername());
        assertEquals("negaodetirarochapeu", user.getPassword());
        assertEquals("1",                   Integer.toString(user.getOperador()));
        assertEquals("21515151515",         user.getCpf());
        assertEquals("al.cione@gmail.com",  user.getEmail());
        assertEquals("02021972",            user.getDataNascimento());
        assertEquals("Alcioninha",          user.getNomeCracha());
        assertEquals("Mulherona",           user.getSexo());
        assertEquals("Rua da Alcione",      user.getEndereco());
        assertEquals("Paris",               user.getCidade());
        assertEquals("SP",                  user.getEstado());
        assertEquals("Brasil",              user.getPais());
        assertEquals("87240-364",           user.getCep());
        assertEquals("01177777777",         user.getTelefone());
        assertEquals("01188888888",         user.getCelular());

        System.out.println("* Unit_Test: F testeUsuario");
    }

    public long testeInsertUsuarioBanco() throws SQLException, ClassNotFoundException {
        System.out.println("* Unit_Test: I testeInsertUsuarioBanco");
        
        ControllerUsuario uc = ControllerUsuario.getInstance();
        int count = db.getTableCount("usuarios");
        Usuario user = new Usuario("Alcione", "Alcione55", "negaodetirarochapeu", 1, "21515151515", "al.cione@gmail.com",
                "02021972", "Alcioninha", "Mulherona", "Rua da Alcione", "Paris", "SP", "Brasil",
                "87240-364", "01177777777", "01188888888");
        long id = uc.insert(user);

        assertEquals(count+1, db.getTableCount("usuarios"));
        
        System.out.println("* Unit_Test: F testeInsertUsuarioBanco");
        return id;
    }
    
    public void testeUpdateUsuarioBanco(long id) throws SQLException {
        System.out.println("* Unit_Test: I testeUpdateUsuarioBanco");
        
        ControllerUsuario uc = ControllerUsuario.getInstance();
        int count = db.getTableCount("usuarios");
        Usuario user = new Usuario("Alcione", "Alcione55", "negaodetirarochapeu", 1, "21515151515", "al.cione@gmail.com",
                "02021972", "Alcioninha", "Mulheraça", "Rua da Alcione", "Paris", "SP", "Brasil",
                "87240-364", "01177777777", "01188888888");
        user.setId(id);
        long n = uc.update(user);

        assertEquals(1, n);
        assertEquals(count, db.getTableCount("usuarios"));

        System.out.println("* Unit_Test: F testeUpdateUsuarioBanco");
    }
    
    public void testeSelectUsuarioBanco(long id) throws SQLException {
        System.out.println("* Unit_Test: I testeSelectUsuarioBanco");

        Usuario user = new Usuario();
        
        ControllerUsuario uc = ControllerUsuario.getInstance();
        
        user = uc.getByID(id);
        
        assertEquals("Alcione",             user.getNome());
        assertEquals("Alcione55",           user.getUsername());
        assertEquals("negaodetirarochapeu", user.getPassword());
        assertEquals("1",                   Integer.toString(user.getOperador()));
        assertEquals("21515151515",         user.getCpf());
        assertEquals("al.cione@gmail.com",  user.getEmail());
        assertEquals("02021972",            user.getDataNascimento());
        assertEquals("Alcioninha",          user.getNomeCracha());
        assertEquals("Mulheraça",           user.getSexo());
        assertEquals("Rua da Alcione",      user.getEndereco());
        assertEquals("Paris",               user.getCidade());
        assertEquals("SP",                  user.getEstado());
        assertEquals("Brasil",              user.getPais());
        assertEquals("87240-364",           user.getCep());
        assertEquals("01177777777",         user.getTelefone());
        assertEquals("01188888888",         user.getCelular());
        
        System.out.println("* Unit_Test: F testeSelectUsuarioBanco");
    }
}
